import { request } from '@umijs/max';

// 创建客户
export async function createCustomer(body: any, options?: { [key: string]: any }) {
  return request('/admin/customers', {
    method: 'POST',
    data: body,
    ...(options || {}),
  });
}

// 查询客户信息
export async function getCustomerList(params?: any, options?: { [key: string]: any }) {
  return request('/admin/customers', {
    method: 'GET',
    params,
    ...(options || {}),
  });
}

// 更新客户信息
export async function updateCustomer(user_id: number, body: any, options?: { [key: string]: any }) {
  return request(`/admin/customers/${user_id}`, {
    method: 'PUT',
    data: body,
    ...(options || {}),
  });
}

// 删除客户
export async function deleteCustomer(user_id: number, options?: { [key: string]: any }) {
  return request(`/admin/customers/${user_id}`, {
    method: 'DELETE',
    ...(options || {}),
  });
}

// 重置客户账户密码
export async function resetCustomerPassword(user_id: number, options?: { [key: string]: any }) {
  return request(`/admin/customers/${user_id}/reset-password`, {
    method: 'PUT',
    ...(options || {}),
  });
}

// 存款
export async function customerDeposit(cardId: string, params: { amount: number; remark?: string }, options?: any) {
  return request(`/api/customers/cards/${cardId}/deposit`, {
    method: 'POST',
    params,
    ...(options || {}),
  });
}

// 取款
export async function customerWithdraw(body: { cardId: string; amount: number; password: string; remark?: string }, options?: any) {
  return request('/api/customers/cards/withdraw', {
    method: 'POST',
    data: body,
    ...(options || {}),
  });
}

// 转账
export async function customerTransfer(body: { fromCardId: string; toCardId: string; amount: number; password: string; remark?: string }, options?: any) {
  return request('/api/customers/transfer', {
    method: 'POST',
    data: body,
    ...(options || {}),
  });
}

// 挂失/解挂
export async function reportCardLoss(cardId: string, options?: any) {
  return request(`/api/customers/cards/${cardId}/report-loss`, {
    method: 'POST',
    ...(options || {}),
  });
}

// 修改银行卡密码
export async function updateCardPassword(body: { cardId: string; oldPassword: string; newPassword: string }, options?: any) {
  return request('/api/customers/cards/password', {
    method: 'PUT',
    data: body,
    ...(options || {}),
  });
}

// 修改用户账户密码
export async function updateUserPassword(body: {
  old_password: string;
  new_password: string;
}, options?: { [key: string]: any }) {
  return request('/customers/password', {
    method: 'PUT',
    data: body,
    ...(options || {}),
  });
}

// 获取当前用户银行卡列表（GET + params）
export async function getMyCardList(params: any, options?: { [key: string]: any }) {
  return request('/api/customers/cards/list', {
    method: 'GET',
    params,
    ...(options || {}),
  });
}

// 获取当前客户信息
export async function getCurrentCustomerInfo(options?: { [key: string]: any }) {
  return request('/api/customers/me', {
    method: 'GET',
    ...(options || {}),
  });
}

// 修改当前客户信息
export async function updateCurrentCustomerInfo(body: any, options?: { [key: string]: any }) {
  return request('/api/customers/me', {
    method: 'PUT',
    data: body,
    ...(options || {}),
  });
} 